﻿using PlutoStudio.Net.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace PlutoStudio.Net.Processors
{
    public abstract class ProcessorBase : IMessageProcessor
    {
        internal protected NetContext Context { get; private set; }
        public virtual IMessage Message { get; private set; }
        public EndPoint RemoteEndPoint { get; private set; }

        void IMessageProcessor.Process(NetContext context, ReceivedEventArgs e)
        {
            TraceHelper.Helper.TraceInformation(string.Format("正在处理消息:{0}", e.Message));
            this.Context = context;
            this.Message = e.Message;
            this.RemoteEndPoint = e.RemoteEndPoint;
            this.Execute();
        }

        protected abstract void Execute();
    }

    public abstract class ProcessorBase<TMessage> : ProcessorBase where TMessage : class,IMessage
        {
            public new virtual TMessage Message
            {
                get
                {
                    return base.Message as TMessage;
                }
            }
        }

}
